import { SecordSubmitAction } from '../actions'
import { PicType } from '../Types'
import { 
  GetSecordSubmitList_PENDING, 
  GetSecordSubmitList_FULFILLED,
  GetSecordSubmitList_Type,
  RECORD_SecordSubmit_FULFILLED } from '../Constants'
// 初始化
const initState= {
  loading: false,
  record: [],
  list: [],
  type: 1,
}
export function SecordSubmitReducer(state: PicType = initState, action: SecordSubmitAction): PicType {
  switch (action.type) {
    case GetSecordSubmitList_PENDING:
      return { ...state, loading: true }
    case GetSecordSubmitList_Type:
      return { ...state, type: action.payload }
    case GetSecordSubmitList_FULFILLED:
      let list = state.list
      if (state.type == 1) list = action.payload.list
      else list = [
        ...state.list||[],
        ...action.payload.list
      ]
      return { 
        ...state, 
        loading: false, 
        list
      }
    case RECORD_SecordSubmit_FULFILLED:
      return { ...state, record: action.payload }
  }
  return state
}